import request from "@/utils/request";
import { getRefreshToken } from "@/utils/auth";
// 登录方法
export function login(data) {
  return request({
    url: "user/phc_login/",
    method: "post",
    data: data,
    // headers: { GroupType: "pc" },
  });
}

export function loginByPassword(data) {
  return request({
    url: "/user/up_login/",
    method: "post",
    data,
  });
}

// 退出方法
export function logout() {
  return request({
    url: "user/logout/",
    method: "post",
  });
}

export function getUserInfo() {
  return request({
    url: "user/userinfo/",
    method: "get",
  });
}
// 刷新访问令牌
export function refreshToken() {
  return request({
    url: "/system/auth/refresh-token?refreshToken=" + getRefreshToken(),
    method: "post",
  });
}

// 请求背景图片和验证图片
export function getVerCode(data) {
  return request({
    url: "system/captcha/get",
    headers: {
      notToken: true,
    },
    method: "post",
    data,
  });
}

// 滑动或者点选验证
export function reqCheck(data) {
  return request({
    url: "system/captcha/check",
    headers: {
      notToken: true,
    },
    method: "post",
    data,
  });
}

export function smsCode(params) {
  return request({
    url: "user/send_sms?phone=" + params,
    headers: {
      notToken: true,
    },
    method: "get",
  });
}

export const register = (data) => {
  return request({
    url: "user/register/",
    data: data,
    method: "post",
  });
};

export const changeUserInfo = ({ is_up_login }) => {
  return request({
    url: "user/userinfo/",
    data: { is_up_login },
    method: "post",
  });
};
